<template>

  <div>
    <div >
      <el-breadcrumb separator="/">
        <!--     <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>-->
        <!--     <el-breadcrumb-item><a href="/">活动管理</a></el-breadcrumb-item>-->
        <el-breadcrumb-item>商品管理</el-breadcrumb-item>
        <el-breadcrumb-item>商品类别管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>


    <div>

      <el-form :inline="true" :model="forObject"  style="margin-top: 15px" class="demo-form-inline">
        <el-form-item label="名称" style="float: left">
          <el-input v-model="forObject.name" placeholder="名称"></el-input>
        </el-form-item>

        <el-form-item label="商品类别描述" style="float: left">
          <el-input v-model="forObject.summary" placeholder="商品类别描述"></el-input>
        </el-form-item>
        <el-form-item style="margin-left: 10px">
          <el-button type="primary"  @click="_onSearch">查询</el-button>
        </el-form-item>
      </el-form>
    </div>


    <div style="float: left;margin-top: 8px;margin-bottom: 8px">
      <el-button type="primary" @click="_add">添加</el-button>
    </div>


    <div style="margin-top: 20px">

      <el-table
        :data="getPage"
        border
        height="500"
        style="width: 100%">
        <el-table-column v-for="item in columnName" :key="item.id" :label="item.label" >
          <template slot-scope="scope">
            <span>{{scope.row[item.prop]}}</span>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
            <el-button @click="_edit(scope.row)" type="text" size="small">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 20, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>


    </div>
    <GoodsCategoryEdit ref="goodsCategoryEditRef"  @on-result-change="_page"></GoodsCategoryEdit>
  </div>

</template>

<script>

  import  GoodsCategoryEdit from  './GoodsCategoryEdit'
  export default {

    mounted(){
      this._page();
    },
    components:{
      GoodsCategoryEdit
    },
    name: "Home",
    data(){
      return {
        forObject:{
          name:undefined,
          summary:undefined
        },
        currentPage:1, //初始页
        pageSize:10,    //    每页的数据
        total:0,    //    每页的数据
        getPage:[],
        columnName:[
          {prop:"name",label:"名称",width:"120",fixed:true},
          {prop:"summary",label:"商品类别描述",width:"120"},
          {prop:"ctime",label:"添加时间",width:"120"},
        ],
      }
    },
    methods:{
      handleClick(data){
        console.log(data);
      },

      handleSizeChange(val) {
        this.pageSize=val;
        this._page();
      },
      handleCurrentChange(val) {
        this.currentPage=val;
        this._page();
      },

      _page(){

        this.$http.post('/t_category/page?rows='+this.pageSize+'&page='+this.currentPage,this.forObject).then(res=>{
          let data= res.data.data;
          this.getPage=data.records;
          console.log('----------------data',data)
          console.log('-----------------',data.total)
          this.total=data.total;
        }).catch(err=>{
          console.log(err)
        });
      },

      _edit(row){
        console.log(row);
        this.$refs.goodsCategoryEditRef._open(row);
      },

      _add(){
        this.$refs.goodsCategoryEditRef._open();
      },

      _onSearch(){
          console.log('------------------------',this.forObject)
          this._page();
      }


    },
  }
</script>

<style scoped>

</style>
